package com.dopios.services.webapp.utilities;

import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * Created with IntelliJ IDEA.
 * User: Guzzler
 * Date: 16/9/2013
 * Time: 2:32 πμ
 * To change this template use File | Settings | File Templates.
 */
public  class TagsManager {
    private static final Logger logger = Logger.getLogger(TagsManager.class);

    public static List<Map<String,Object>> getMatchedTags(String text,List<Map<String,Object>> tags){
        List<Map<String,Object>> matchedTags = new ArrayList();
       StringTokenizer st= tokenize(text);
       while(st.hasMoreElements()){
        String token =(String)st.nextElement();
        for(Map tagRow:tags){
           String keyword =  (String)tagRow.get("keyword");
           if(token.toLowerCase().contains(keyword.toLowerCase())){
               logger.info("Matched tag:"+ (String)tagRow.get("tag")+ " for keyword:"+ (String)tagRow.get("keyword") );
               matchedTags.add(tagRow);
           }
        }
        }
        return matchedTags;
    }
    public static StringTokenizer tokenize(String text){
        StringTokenizer st = new StringTokenizer(text);
       return st;
    }
}
